package vip.geeker.iotms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import vip.geeker.iotms.help.Response;
import vip.geeker.iotms.persistance.mapper.DeviceDataMapper;
import vip.geeker.iotms.persistance.model.DeviceData;
import vip.geeker.iotms.service.IDeviceDataService;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class DeviceDataService extends ServiceImpl<DeviceDataMapper, DeviceData> implements IDeviceDataService {

    @Resource
    private DeviceDataMapper deviceDataMapper;


    @Override
    public Response<PageInfo> queryPage(DeviceData data) {
        PageHelper.startPage(data.getPageNo(), data.getPageSz());
        List<DeviceData> list = deviceDataMapper.queryPage(data);
        PageInfo page = new PageInfo(list);
        return new Response<>(page);
    }

    @Override
    @Transactional
    public Boolean insertByBatch(List<DeviceData> list) {
        if(ObjectUtils.isEmpty(list)){
            return false;
        }
        for (DeviceData data:list) {
            deviceDataMapper.insertSelective(data);
        }
        return true;
    }
}
